package com.reins.bookstore.entity;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;


import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
@Entity
@Table(name = "book")
@JsonIgnoreProperties(value = {"handler","hibernateLazyInitializer","fieldHandler"})
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "bookId")
public class Book {

    @Id
    @Column(name = "id")
    private int bookId;

    private String isbn;
    private String name;
    private String type;
    private String author;
    private BigDecimal price;
    private String description;
    private Integer inventory;
    private String image;

    @JsonIgnoreProperties(value = {"book"})
    @OneToMany(fetch = FetchType.LAZY,targetEntity =  OrderItem.class,mappedBy = "book")
    private List<OrderItem> orderItems = new ArrayList<>();


    public Book(int bookId, String isbn, String name, String type, String author, BigDecimal price, String description, Integer inventory, String image){
        this.bookId = bookId;
        this.isbn = isbn;
        this.name = name;
        this.type = type;
        this.author = author;
        this.price = price;
        this.description = description;
        this.inventory = inventory;
        this.image = image;
    }
    public Book(){
    }

//    @Override
//    public String toString(){
//        return "Book [bookId="+bookId+", isbn="+isbn+", name="+name+", type="+type+", author="+author+", price="+price+", description="+description+", iventory="+inventory+", image="+image+"]";
//    }
}
